package com.bifang.common.util;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DecodeUnicodeUtil {
    public static String ascii2native(String ascii) {
        List<String> ascii_s = new ArrayList<String>();

        String zhengz = "\\\\u[0-9,a-f,A-F]{4}";

        Pattern p = Pattern.compile(zhengz);

        Matcher m = p.matcher(ascii);

        while (m.find()) {
            ascii_s.add(m.group());
        }
        for (int i = 0, j = 2; i < ascii_s.size(); i++) {
            String code = ascii_s.get(i).substring(j, j + 4);
            char ch = (char) Integer.parseInt(code, 16);
            ascii = ascii.replace(ascii_s.get(i), String.valueOf(ch));
        }
        return ascii;
    }
}
